home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import com.sun.java.accessibility.Accessible;
- import com.sun.java.accessibility.AccessibleContext;
- import com.sun.java.swing.plaf.ToolBarUI;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.beans.PropertyChangeListener;
-
- public class JToolBar extends JComponent implements Accessible {
- private boolean paintBorder = true;
- private Insets margin = null;
- private boolean floatable = true;
-
- public JToolBar() {
- ((Container)this).setLayout(new BoxLayout(this, 0));
- this.updateUI();
- }
-
- public JButton add(Action a) {
- JButton b = new JButton((String)a.getValue("Name"), (Icon)a.getValue("SmallIcon"));
- ((AbstractButton)b).setHorizontalTextPosition(0);
- ((AbstractButton)b).setVerticalTextPosition(3);
- ((AbstractButton)b).setEnabled(a.isEnabled());
- ((AbstractButton)b).addActionListener(a);
- ((Container)this).add(b);
- PropertyChangeListener actionPropertyChangeListener = this.createActionChangeListener(b);
- a.addPropertyChangeListener(actionPropertyChangeListener);
- return b;
- }
-
- public void addSeparator() {
- Separator s = new Separator(this);
- ((Container)this).add(s);
- }
-
- protected PropertyChangeListener createActionChangeListener(JButton b) {
- return new ActionChangedListener(this, b);
- }
-
- public AccessibleContext getAccessibleContext() {
- if (super.accessibleContext == null) {
- super.accessibleContext = new AccessibleJToolBar(this);
- }
-
- return super.accessibleContext;
- }
-
- public Component getComponentAtIndex(int i) {
- int ncomponents = ((Container)this).getComponentCount();
- if (i <= ncomponents) {
- Component[] component = ((Container)this).getComponents();
- return component[i];
- } else {
- return null;
- }
- }
-
- public int getComponentIndex(Component c) {
- int ncomponents = ((Container)this).getComponentCount();
- Component[] component = ((Container)this).getComponents();
-
- for(int i = 0; i < ncomponents; ++i) {
- Component comp = component[i];
- if (comp == c) {
- return i;
- }
- }
-
- return -1;
- }
-
- public Insets getMargin() {
- return this.margin == null ? new Insets(0, 0, 0, 0) : this.margin;
- }
-
- public ToolBarUI getUI() {
- return (ToolBarUI)super.ui;
- }
-
- public String getUIClassID() {
- return "ToolBarUI";
- }
-
- public boolean isBorderPainted() {
- return this.paintBorder;
- }
-
- public boolean isFloatable() {
- return this.floatable;
- }
-
- protected void paintBorder(Graphics g) {
- if (this.isBorderPainted()) {
- super.paintBorder(g);
- }
-
- }
-
- public void setBorderPainted(boolean b) {
- this.paintBorder = b;
- ((Container)this).invalidate();
- }
-
- public void setFloatable(boolean b) {
- if (this.floatable != b) {
- this.floatable = b;
- ((JComponent)this).firePropertyChange("floatable", !this.floatable, this.floatable);
- }
-
- }
-
- public void setMargin(Insets m) {
- Insets old = this.margin;
- this.margin = m;
- ((JComponent)this).firePropertyChange("margin", old, m);
- ((Container)this).invalidate();
- }
-
- public void setUI(ToolBarUI ui) {
- super.setUI(ui);
- }
-
- public void updateUI() {
- this.setUI((ToolBarUI)UIManager.getUI(this));
- ((Container)this).invalidate();
- }
- }
-